package com.furentech.iotserver.fa.sinopec.sinopec_processor;

import com.alibaba.druid.sql.visitor.functions.Hex;
import com.furentech.iotserver.fa.sinopec.SinopecFunCode;
import com.furentech.iotserver.fa.sinopec.SinopecRestRequest;
import com.furentech.iotserver.fa.utils.HexStringUtils;
import io.netty.channel.Channel;
import org.springframework.stereotype.Component;


@Component
public class WBListCheck_Processor extends SinopecProcessorBase {
    @Override
    String actualGetJsonString(byte[] buf) {
        return null;
    }

    @Override
    String actualGetReadableString(byte[] buf) {
        return String.format("加油机请求查询黑白名单:%s", HexStringUtils.toHexString(buf, 1, 10));
    }

    @Override
    byte[] actualGetResponse(byte[] buf, Channel channel) {

        byte[] responseBuf = new byte[12];

        responseBuf[0] = SinopecFunCode.BWList_Result & 0x00ff;

        String carNum = HexStringUtils.toHexString(buf, 1, 10);

        if (SinopecRestRequest.isCardNumInWBList(carNum)) {
            responseBuf[1] = 0;
        } else {
            responseBuf[1]= 1 ;
        }
        System.arraycopy(buf, 1, responseBuf, 2, 10);

        return responseBuf;
    }
}
